package com.fpx.open.platform.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.validator.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 客户帐户实体类，包含客户访问API的用户信息
 * 
 * @author sunkey
 * @date Apr 2, 2013 9:47:25 AM
 * @version 1.0.0
 * @copyright fpx.com
 */
@XmlRootElement
public class UserInfo extends ParentDomain implements Serializable {
	/**
	 * 帐户ID, (用户id)
	 */
	private Integer userId;
	/**
	 * 客户ID(客户表ID)
	 */
	@JsonIgnore
	@XmlTransient
	private String companyName;
	/**
	 * 用户名(获取token时需要)
	 */
	@NotEmpty
	@Size(max = 16)
	// 用户名不允许超过16个字符
	private String userName;
	/**
	 * 用户密码(获取token时需要)
	 */
	@NotEmpty
	@Size(max = 16)
	private String password;
	/**
	 * API接口令牌
	 */
	@XmlTransient
	private String token;
	/**
	 * 是否有效,1:有效，0：无效
	 */
	@XmlTransient
	private Integer isEffect;
	/**
	 * 更新时间
	 */
	@XmlTransient
	private Date dateUpdated;

	@XmlTransient
	private Date dateCreated;

	/**
	 * 访问频率
	 */
	@XmlTransient
	private Integer frequency;
	
	/**
	 * 有效天数，默认为0 不过期
	 */
	@XmlTransient
	private Short expireday;

	@XmlTransient
	List<RelUserCustomer> relUserCustomers;

	private static final long serialVersionUID = 1L;
	
	/**
	 * 用户类型 XMS、OMS
	 */
	private String userType;

	@JsonIgnore
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer UserId) {
		this.userId = UserId;
	}

	@JsonIgnore
	public String getUserName() {
		return userName;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public void setUserName(String userName) {
		this.userName = userName == null ? null : userName.trim();
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password == null ? null : password.trim();
	}

	@JsonIgnore
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token == null ? null : token.trim();
	}

	@JsonIgnore
	public Integer getIsEffect() {
		return isEffect;
	}

	public void setIsEffect(Integer isEffect) {
		this.isEffect = isEffect;
	}

	@JsonIgnore
	public Date getDateUpdated() {
		return dateUpdated;
	}

	@JsonIgnore
	public Integer getFrequency() {
		return frequency;
	}

	public void setFrequency(Integer frequency) {
		this.frequency = frequency;
	}

	@JsonIgnore
	public List<RelUserCustomer> getRelUserCustomers() {
		return relUserCustomers;
	}
	
	public void setRelUserCustomers(List<RelUserCustomer> relUserCustomers) {
		this.relUserCustomers = relUserCustomers;
	}
	
	
	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}


	@JsonIgnore
	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	@JsonIgnore
	public Short getExpireday() {
		return expireday;
	}

	public void setExpireday(Short expireday) {
		this.expireday = expireday;
	}

	public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        UserInfo other = (UserInfo) that;
        return (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
            && (this.getCompanyName() == null ? other.getCompanyName() == null : this.getCompanyName().equals(other.getCompanyName()))
            && (this.getUserName() == null ? other.getUserName() == null : this.getUserName().equals(other.getUserName()))
            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
            && (this.getToken() == null ? other.getToken() == null : this.getToken().equals(other.getToken()))
            && (this.getIsEffect() == null ? other.getIsEffect() == null : this.getIsEffect().equals(other.getIsEffect()))
            && (this.getDateUpdated() == null ? other.getDateUpdated() == null : this.getDateUpdated().equals(other.getDateUpdated()))
            && (this.getDateCreated() == null ? other.getDateCreated() == null : this.getDateCreated().equals(other.getDateCreated()))
            && (this.getFrequency() == null ? other.getFrequency() == null : this.getFrequency().equals(other.getFrequency()))
            && (this.getExpireday() == null ? other.getExpireday() == null : this.getExpireday().equals(other.getExpireday()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
        result = prime * result + ((getCompanyName() == null) ? 0 : getCompanyName().hashCode());
        result = prime * result + ((getUserName() == null) ? 0 : getUserName().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getToken() == null) ? 0 : getToken().hashCode());
        result = prime * result + ((getIsEffect() == null) ? 0 : getIsEffect().hashCode());
        result = prime * result + ((getDateUpdated() == null) ? 0 : getDateUpdated().hashCode());
        result = prime * result + ((getDateCreated() == null) ? 0 : getDateCreated().hashCode());
        result = prime * result + ((getFrequency() == null) ? 0 : getFrequency().hashCode());
        result = prime * result + ((getExpireday() == null) ? 0 : getExpireday().hashCode());
        return result;
    }
}